package com.hualan.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.PsychologyTestResultMapper;
import com.hualan.sfzy.model.entity.PsychologyTestClassify;
import com.hualan.sfzy.model.entity.PsychologyTestResult;
import com.hualan.sfzy.service.BaseService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PsychologyTestResultServiceImpl implements BaseService<PsychologyTestResult> {
    @Autowired
    private PsychologyTestResultMapper psychologyTestResultMapper;

    /*增加*/
    @Override
    public int add(PsychologyTestResult entity) {
        return psychologyTestResultMapper.insert(entity);
    }

    /*修改*/
    @Override
    public int edit(PsychologyTestResult entity) {
        return psychologyTestResultMapper.update(entity);
    }

    /*删除*/
    @Override
    public int remove(Integer id) {
        return psychologyTestResultMapper.delete(id);
    }

    /*批量删除*/
    @Override
    public int removeBatch(Integer[] ids) {
        return psychologyTestResultMapper.deleteBatch(ids);
    }

    /*查询所有*/
    @Override
    public List<PsychologyTestResult> find() {
        return psychologyTestResultMapper.select(null);
    }

    /*分页查询(单表)*/
    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, PsychologyTestResult entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<PsychologyTestResult> list = psychologyTestResultMapper.select(entity);
        PageInfo<PsychologyTestResult> pageInfo = new PageInfo<>(list); // 分页信息对象
        Map<String, Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    /*根据id查询(单表)*/
    @Override
    public PsychologyTestResult findById(Integer id) {
        return psychologyTestResultMapper.selectById(id);
    }

    /*多表根据id查询单个(多表)*/
    public PsychologyTestResult findByIdDuo(Integer id) {
        return psychologyTestResultMapper.selectByIdDuo(id);
    }

    /*多表查询(分页 多表)*/
    public Map<String, Object> findDuo(Integer pageNum, Integer pageSize, PsychologyTestResult entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<PsychologyTestResult> list = psychologyTestResultMapper.selectDuo(entity);
        PageInfo<PsychologyTestResult> pageInfo = new PageInfo<>(list); // 分页信息对象
        Map<String, Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }
    /**根据用户id查询测评结果*/
    public List<PsychologyTestResult> selSysUserId(Integer userId,Integer testId){
        return psychologyTestResultMapper.selByUserId(userId,testId);
    }
    /**根据用户id查询测评结果*/
    public List<PsychologyTestResult> sellectByUserId(Integer userId){
        return psychologyTestResultMapper.selectByUserId(userId);
    }
}
